package com.demo.project_template.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.demo.project_template.entity.Post;
import com.demo.project_template.entity.PostLike;
import com.demo.project_template.mapper.PostLikeMapper;
import com.demo.project_template.mapper.PostMapper;
import com.demo.project_template.service.PostService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 用户帖子 服务实现类
 * </p>
 *
 * @author 杨玉龙
 * @since 2024-08-20 11:48:57
 */
@Service
public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements PostService {
    @Resource
    private PostLikeMapper postLikeMapper;

    @Override
    public void handlePost(List<Post> posts,Long userId){
        posts.forEach(item->{
            Long count = postLikeMapper.selectCount(new LambdaQueryWrapper<PostLike>().eq(PostLike::getPostId, item.getId()).eq(PostLike::getUserId, userId));
            item.setIsLike(count.intValue());
        });
    }
}
